From da3db83dc566acb5987a444e28e6e5ee2a5ad2a7 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Tue, 16 Aug 2016 22:51:08 +0200 Subject: [PATCH] Trunchate cargo config properly --- src/cargo/util/config.rs | 1 + tests/registry.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 329538663..21d68c1ce 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -732,5 +732,6 @@ pub fn set_config(cfg: &Config, let contents = toml::Value::Table(toml).to_string(); try!(file.seek(SeekFrom::Start(0))); try!(file.write_all(contents.as_bytes())); + try!(file.file().set_len(contents.len() as u64)); Ok(()) } diff --git a/tests/registry.rs b/tests/registry.rs index 0ddb55999..1a069f562 100644 --- a/tests/registry.rs +++ b/tests/registry.rs @@ -580,6 +580,19 @@ fn login_with_no_cargo_dir() { execs().with_status(0)); } +#[test] +fn login_with_differently_sized_token() { + // Verify that the configuration file gets properly trunchated. + let home = paths::home().join("new-home"); + t!(fs::create_dir(&home)); + assert_that(cargo_process().arg("login").arg("lmaolmaolmao").arg("-v"), + execs().with_status(0)); + assert_that(cargo_process().arg("login").arg("lmao").arg("-v"), + execs().with_status(0)); + assert_that(cargo_process().arg("login").arg("lmaolmaolmao").arg("-v"), + execs().with_status(0)); +} + #[test] fn bad_license_file() { Package::new("foo", "1.0.0").publish(); -- 2.30.2